home *** CD-ROM | disk | FTP | other *** search
- Path: mudskipper.cac.psu.edu!user
- From: fcusack@tdx.org (frank.)
- Newsgroups: comp.lang.c++
- Subject: Re: Pointer to non-static function
- Date: Fri, 08 Mar 1996 09:35:05 -0400
- Organization: Soylent Green is People!!
- Message-ID: <fcusack-0803960935050001@mudskipper.cac.psu.edu>
- References: <4hnsfs$cp2@nntp.ucs.ubc.ca>
- NNTP-Posting-Host: mudskipper.cac.psu.edu
-
- In article <4hnsfs$cp2@nntp.ucs.ubc.ca>, jamesdf@unixg.ubc.ca (James
- Fairweather) wrote:
-
- > I am attempting to make some code I've written more elegant by using a
- > pointer to a function. Here's how I declare the pointer:
- >
- > double (*f)(double);
- >
- > Now I'd like to make f point to one of two functions, one declared as:
- >
- > double CFunction::Calculate(double);
- >
- > and the other as:
- >
- > double CEquation::Calculate(double);
- >
- > Neither are static, and CEquation and CFunction are not related by
- > inheritance. Nor can they be, since CEquation contains a list of
- > CFunctions.
- >
- > At compile time, the compiler issues an error, "cannot convert from
- > double (CFunction::*)(double) to double (__cdecl *)(double)" and
- > "cannot convert from double (CEquation::*)(double) to double (__cdecl
- > *)(double)".
- >
- > This looks suspiciously like a typecasting problem to me.
-
- yes and no. Don't confuse "functions" with "methods". functions
- (typically) have global or file scope, methods have "class scope" I guess.
-
- You want
-
- double (*CFunction::f)(double);
-
- AFAIK, you wouldn't be able to arbitrarily have it point to a method in
- class CEquation though.
-
- ~Frank
- -- I am Pentium of Borg. Division is futile. You will be approximated. --
- -- PGP ID: 1C0F6685 | NCB#56 | Visit me --> http://www.tdx.org/~fcusack/ --
-